#include "stdinreader.h"


StdInReader::StdInReader(QObject *parent) : QThread(parent)
{
}
StdInReader::~StdInReader()
{

}

void StdInReader::run(){
        QTextStream qin( stdin, QFile::ReadOnly );
        forever
        {
            QString line = qin.readLine();
            if( !line.isEmpty() ){

                if("show" == line) {
                    qDebug() << "onShow";
                    emit(onShow());
                }else if("hide" == line) {
                    qDebug() << "onHide";
                    emit(onHide());
                }else if(line.startsWith("loadfile")){
                    QStringList valName = line.split("=");
                    qDebug() << "loadThisFile"<<valName.at(1);
                    emit(onLoadFile(valName.at(1)));
                }else if(line.startsWith("onLoadPosAndSize")){
                    QStringList valName = line.split("=");
                    qDebug() << "onLoadPosAndSize";
                    qDebug() << "newPos"<<valName.at(1);
                    qDebug() << "newSize"<<valName.at(2);
                    emit(onLoadPosAndSize(valName.at(1),valName.at(2)));
                }else if(line.startsWith("setTitle")){
                    QStringList valName = line.split("=");
                    qDebug() << "setTitle<"<<valName.at(1)<<">";
                    emit(onTitle(valName.at(1)));
                }else{
                    qDebug() << "<" << line <<">";
                    emit(inputLine(line));
                    qDebug() << "emitted" ;
                }
                //else if("hide" == line) emit(onHide());

                /*if( line.toLower() == "q" )
                {
                    break;
                }*/
            }
        }
}


